package com.ocom.payconfig.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ocom.common.entity.typehandler.EntityCcbBusinessInfo;
import com.ocom.common.response.CcbBusinessInfoResponse;
import com.ocom.common.response.CcbBusinessSumResponse;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 智慧生活商家信息 Mapper 接口
 * </p>
 *
 * @author js
 * @since 2023-10-04
 */
@Mapper
public interface IDaoCcbBusinessInfo extends BaseMapper<EntityCcbBusinessInfo> {

    @Select({"<script>",
            "SELECT b.merch_id AS merchId, b.business_id AS businessId , b.business_name AS businessName , b.mrch_id AS mrchId, \n" +
                    "b.branch_id AS branchId , b.mobile , b.create_time AS createTime , m.merch_name AS merchName , \n" +
                    " (SELECT COUNT(vpos_id) FROM `ccb_pos_info` c WHERE c.com_id = #{comId} AND b.business_id =c.business_id GROUP BY  business_id) AS posNum,\n" +
                    " (SELECT SUM(CASE WHEN device_no ='' THEN 0 ELSE 1 END) FROM `ccb_pos_info` c WHERE c.com_id= #{comId} AND b.business_id = c.business_id GROUP BY business_id) AS machNum \n" +
                    "FROM ccb_business_info AS b\n" +
                    "LEFT JOIN `xf_merchant_info` AS m ON m.merch_id=b.merch_id \n" +
                    "WHERE b.com_id= #{comId} \n" +
                    "ORDER BY mrchId"+
                    "</script>"})
    List<CcbBusinessInfoResponse> getCcbBusinessList(Long comId);

/*    @Select({"<script>",
            "SELECT b.merch_id AS merchId, b.business_id AS businessId , b.business_name AS businessName , b.mrch_id AS mrchId,\n" +
                    "b.branch_id AS branchId , b.mobile , b.create_time AS createTime , m.merch_name AS merchName \n" +
                    "FROM ccb_business_info AS b\n" +
                    "LEFT JOIN `xf_merchant_info` AS m ON m.merch_id=b.merch_id \n" +
                    "WHERE b.com_id = #{comId} \n" +
                    "ORDER BY mrchId"+
            "</script>"})
    List<CcbBusinessInfoResponse> getCcbBusinessList(Long comId);*/

    @Select({"<script>",
            "SELECT business_id , COUNT(vpos_id) AS posNum,\n" +
            "SUM(CASE WHEN device_no ='' THEN 0 ELSE 1 END) AS machNum \n" +
            "FROM ccb_pos_info\n" +
            "WHERE com_id = #{comId}\n" +
            "GROUP BY  business_id" +
            "</script>"})
    List<CcbBusinessSumResponse> getCcbBusinessSum(Long comId);
}
